﻿# Will match against all patterns unless explicitly exited
switch (1) {
	1 { "One" }
	1 { "another One" }
	2 { "Two" }
}

# Escape additional matches with break
switch (1) {
	1 { "One"; break }
	1 { "another One" }
	2 { "Two" }
}

# Specify a default action with default
switch (3) {
	1 { "One" }
	2 { "Two" }
	default { "default" }
}

# By default, matches are case-insensitive
switch ("abc") {
	"abc" { "lowercase" }
	"ABC" { "uppercase" }
}

# You can make matches case-sensitive
switch -casesensitive ("abc") {
	"abc" { "lowercase" }
	"ABC" { "uppercase" }
}

# You can convert value to string and match using wildcards
# The original object is passed in to $_
switch -wildcard (123) {
	"1*" { "one-star: $_ $($_.GetType().Name)" }
	"*3" { "start-three: $_ $($_.GetType().Name)" }
}

# You can also match on regular expressions
switch -regex (123) {
	"[1]" { "contains 1" }
	"[23]" { "contains 2 or 3" }
}

# You can match on expressions
switch (5) {
	{ $_ -gt 3 } { "> 3" }
	{ $_ -lt 7 } { "< 7" }
}

# switch will iterate over collection matches
switch (1,2,3,4,5,6) {
	{ $_ % 2 } { "Odd $_"; continue }
	4 { "FOUR" }
	default { "Even $_" }
}
